<?php
/**
 * Notes:
 * User: Lionel
 * DateTime: 2020/10/13 14:23
 */

namespace app\admin\controller;

use app\common\model\User as UserModel;
use app\common\controller\AdminBase;
use think\Config;
use think\Db;

/**
 * 用户管理
 * Class AdminUser
 * @package app\admin\controller
 */
class Cuser extends AdminBase
{
    protected $user_model;

    protected function _initialize()
    {
        parent::_initialize();
        $this->user_model = new UserModel();
    }

    /**
     * 用户管理
     * @param string $keyword
     * @param int    $page
     * @return mixed
     */
    public function ch_index($keyword = '', $page = 1)
    {
        $map['status'] = 1;
        if(input('type')){
            $map['check_time'] = ['>',0];
            $map['warn'] = 0;
        }
        if ($keyword) {
            $map['username|mobile'] = ['like', "%{$keyword}%"];
        } 
        $user_list = Db::name('person')->where($map)->order('id DESC')->paginate(15, false, ['page' => $page]);

        if(!empty($user_list)){

            foreach ($user_list as $k => $val) {
                if(input('type')){
                    Db::name('person')->where(['id'=>$val['id']])->update(['warn'=>1]);
                }
            }
        }
        return $this->fetch('user/index2', ['user_list' => $user_list, 'keyword' => $keyword]);
    }

}
